/*
10001st prime
Problem 7

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

*/

var linq = require('linq');
var start = new Date().getTime();

var isPrime = function (n) {
    if (isNaN(n) || !isFinite(n) || n % 1 || n < 2) {
        return false;
    };

    if (n % 2 == 0) {
        return (n == 2);
    }

    var m = Math.sqrt(n);

    for (var i = 3; i <= m; i += 2) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
};

var primeCounter = 0;
var number = 1;
 while (primeCounter < 10001){
    number++;

    if (isPrime(number))
        primeCounter++;
}

console.log(number);

var end = new Date().getTime();
var time = end - start;

console.log("Time: ", time);

require('readline')
    .createInterface(process.stdin, process.stdout)
    .question("Press [Enter] to exit...", function(){
        process.exit();
});